//
//  FCTableViewCell.m
//  项目三
//
//  Created by rimi1 on 2016/12/10.
//  Copyright © 2016年 Wangxingqian. All rights reserved.
//

#import "FCTableViewCell.h"

static NSInteger spacing_ = 10;

@implementation FCTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView addSubview:self.headImage];
        [self.contentView addSubview:self.name];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    if (self.isCancel) {
        [self.contentView addSubview:self.cancel];
    }
}

#pragma mark - respondsTo...

- (void)respondsToCancel:(UIButton *)sender {
    [self.delegate fcTableViewCell:self tapOfCancel:sender];
}

#pragma mark - get

- (UIImageView *)headImage {
    
    if (!_headImage) {
        
        CGFloat diameter = 50;
        _headImage = [[UIImageView alloc] initWithFrame:CGRectMake(spacing_/2, spacing_/2, diameter, diameter)];
        _headImage.layer.cornerRadius = diameter/2;
        _headImage.layer.masksToBounds = YES;
        
    }
    return _headImage;
}

- (UILabel *)name {
    
    if (!_name) {
        
        CGFloat x = CGRectGetMaxX(self.headImage.frame) + spacing_;
        _name = [[UILabel alloc] initWithFrame:CGRectMake(x, 0, kWIDTH - x - spacing_, CGRectGetHeight(self.headImage.bounds) + spacing_ * 2)];
        
    }
    return _name;
}

- (UIButton *)cancel {
    
    if (!_cancel) {
        
        CGFloat width = 70;
        CGFloat spacing = spacing_ + 5;
        _cancel = [[UIButton alloc] initWithFrame:CGRectMake(kWIDTH - spacing - width, spacing, width, 30)];
        _cancel.layer.borderColor = [UIColor blackColor].CGColor;
        _cancel.layer.borderWidth = 1;
        _cancel.layer.cornerRadius = 5;
        _cancel.layer.masksToBounds = YES;
        _cancel.titleLabel.font = [UIFont systemFontOfSize:14];
        [_cancel setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [_cancel addTarget:self action:@selector(respondsToCancel:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _cancel;
}

@end














